﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPI.ProjectDomain.Infrastructure.DbObject;
using System.Data.SqlClient;
using KPI.ProjectDomain.Model.Entity;

namespace KPI.ProjectDomain.Infrastructure.DbManager
{
   public class ProjectManager
    {
       public ProjectTab CreatProject(ProjectTab projectTab, SqlConnection kpiConnection, SqlTransaction transaction)
       {
           SqlCommand command = kpiConnection.CreateCommand();
           if (transaction != null) command.Transaction = transaction;

           command.CommandText = @"insert into Project([Name], [Description], FirstProjectManagerID, CreatedDate, LastModifiedDate, Version, IsDeleted) 
values(@name, @description, @FirstProjectManagerID, @createdDate, @lastModifiedDate, 0, 0); 
select @newID=SCOPE_IDENTITY()";

           projectTab.LastModifiedDate = DateTime.Now;
           projectTab.Version = 0;
           projectTab.IsDeleted = false;

           command.Parameters.Add(new SqlParameter("@name", projectTab.Name));
           command.Parameters.Add(new SqlParameter("@description", projectTab.Description));
           command.Parameters.Add(new SqlParameter("@FirstProjectManagerID", projectTab.FirstProjectManagerID));
           command.Parameters.Add(new SqlParameter("@createdDate", projectTab.CreatedDate));
           command.Parameters.Add(new SqlParameter("@lastModifiedDate", projectTab.LastModifiedDate));

           // not Finish 2013/2/7

           //SqlParameter newID = new SqlParameter("@newId", SqlDbType.Int);
           //newID.Direction = ParameterDirection.Output;
           //command.Parameters.Add(newID);

           //command.ExecuteNonQuery();

           //department.DepartmentID = Convert.ToInt32(newID.Value);
           //return department;

           return null;
       }

    }
}
